package com.example.mvc_test.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.view.InternalResourceViewResolver;
import org.springframework.web.servlet.view.JstlView;

/**
 * @author ljw
 * @description
 * @date 2021/9/15 8:04
 */
@EnableWebMvc
@Configuration
@ComponentScan("com.example.mvc_test")
public class MyConfig extends WebMvcConfigurerAdapter {

    /**
     * 内部资源视图解析器
     * @author ljw
     * @date 2021/9/15 8:11
     */
    @Bean
    public InternalResourceViewResolver viewResolver() {
        InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
        viewResolver.setPrefix("/WEB-INF/classes/views/");
        viewResolver.setSuffix(".jsp");
        viewResolver.setViewClass(JstlView.class);
        return viewResolver;
    }

    /**
     * 静态资源简单映射
     * @param registry 注册器
     * @author ljw
     * @date 2021/9/15 8:13
     */
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
    }
}
